'use strict'
const SystemEnvironment = require('./src/utils/environment')
const path = require('path');
function resolve(dir) {
    return path.join(__dirname, dir)
}

function getServerAddress(){
    return SystemEnvironment.getApiBaseUrl();
}

module.exports = {
    publicPath: process.env.NODE_ENV === 'production'  ? './' : '/',
    lintOnSave: true,
    devServer:{
        host: '0.0.0.0',
        port: 8082,
        open: true,
        proxy:{
            [process.env.VUE_APP_BASE_URL]: {
                target: getServerAddress(),
                changeOrigin: true,
                pathRewrite: {
                    ['^' + process.env.VUE_APP_BASE_URL]: ''
                }
            }
        }
    },
    productionSourceMap: process.env.NODE_ENV === 'development',
    outputDir:"dist",
    assetsDir: 'static',
    configureWebpack: {
        name: "YingCode",
        resolve: {
            alias: {
                '@': resolve('src')
            }
        }
    },
    chainWebpack: config =>{
        config
            .when(process.env.NODE_ENV !== 'development',
                config => {
                    config.optimization.runtimeChunk('single'),
                        {
                            from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
                            to: './', //到根目录下
                        }
                }
            )
    }
}